﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReferralTracker.Data.Contexts;

namespace ReferralTracker.BusinessObjects {
    public class DbSession : ISession {
        ReferralTrackerContext _context = null;
        public event EventHandler OnClose;

        public DbSession() {
            _context = new ReferralTrackerContext();
        }

        public DbSession(ReferralTrackerContext context) {
            _context = context;
        }

        public IContext Context {
            get {
                return _context;
            }
        }

        public void Commit() {
            _context.SaveChanges();
        }

        public void Dispose() {
            _context.Dispose();
        }

        public void Close() {
            OnClose(this, EventArgs.Empty);
        }
    }
}
